Policies
Define authorization rules to control access to your application's resources.
Overview
Policies provide fine-grained access control using Cerbos-style policy definitions. Create resource policies, principal policies, and derived roles to determine who can do what in your application.
Concepts
Resource Policy
Defines access rules for a specific resource type (e.g., documents, orders). Specifies which actions are allowed for which roles under what conditions.
Principal Policy
Overrides resource policies for specific users or groups. Useful for granting or denying access to particular individuals.
Derived Roles
Dynamic roles computed from user attributes at runtime. For example, "document_owner" when the user's ID matches the document's owner_id.
View Policies
- Navigate to your App in the Dashboard.
- Click Policies in the sidebar.
- View policies in two modes:
- List View: All policies in a searchable list
- Graph View: Visual representation of policy relationships
Policy Types
Policies are color-coded by type:
- Resource Policies: Blue
- Principal Policies: Orange
- Derived Roles: Green
Policy Editor
The policy editor provides multiple views for working with policies:
Form View
Visual form editor for policy structure:
- Click the Form tab.
- Edit rules using dropdowns and inputs.
- Add conditions using the condition builder.
Code View
YAML/JSON code editor:
- Click the Code tab.
- Edit the policy definition directly.
- Changes sync with the Form view.
Flow View
Visual flowchart of policy rules:
- Click the Flow tab.
- See the decision flow for access checks.
- Understand how rules are evaluated.
Test View
Built-in policy testing:
- Click the Test tab.
- Create test scenarios.
- See pass/fail results for each scenario.
Create a Resource Policy
- Navigate to Policies in your app.
- Click Create Policy.
- Select Resource Policy.
- Configure the policy:
- Resource: The resource type this policy applies to
- Version: Policy version (e.g., "default")
- Add rules:
- Actions: What can be done (read, write, delete)
- Roles: Who can do it (admin, user, guest)
- Conditions: When the rule applies (optional)
- Click Create.
Example Resource Policy
apiVersion: api.cerbos.dev/v1
resourcePolicy:
resource: document
version: default
rules:
- actions:
- read
- write
effect: EFFECT_ALLOW
roles:
- admin
- actions:
- read
effect: EFFECT_ALLOW
roles:
- user
condition:
match:
expr: request.resource.attr.is_published == true
Create a Principal Policy
- Navigate to Policies in your app.
- Click Create Policy.
- Select Principal Policy.
- Configure:
- Principal: User ID or identifier
- Version: Policy version
- Add overrides for specific resources.
- Click Create.
Create Derived Roles
- Navigate to Policies in your app.
- Click Create Policy.
- Select Derived Roles.
- Configure:
- Name: Role set name
- Definitions: Role definitions with conditions
- Click Create.
Example Derived Roles
apiVersion: api.cerbos.dev/v1
derivedRoles:
name: document_roles
definitions:
- name: owner
parentRoles:
- user
condition:
match:
expr: request.resource.attr.owner_id == request.principal.id
Test Policies
- Navigate to a policy.
- Click the Test tab.
- Create test scenarios:
- Principal: User attributes
- Resource: Resource attributes
- Action: Action to test
- Click Run Tests.
- View results showing allowed/denied.
Graph View
Visualize policy relationships:
- Click Graph View in the policies page.
- See connections between:
- Derived Roles and Resource Policies
- Resource Policies and Principal Policies
- Click nodes to view policy details.
Configuration
Policy Fields
| Field | Description | Required |
|---|---|---|
| Resource | Resource type | Yes (Resource Policy) |
| Principal | User identifier | Yes (Principal Policy) |
| Version | Policy version | Yes |
| Rules | Access rules | Yes |
Rule Fields
| Field | Description |
|---|---|
| Actions | List of actions (read, write, etc.) |
| Effect | EFFECT_ALLOW or EFFECT_DENY |
| Roles | Roles this rule applies to |
| Condition | CEL expression for conditional access |
Condition Expressions (CEL)
Common expressions for conditions:
# Check attribute equality
request.resource.attr.owner_id == request.principal.id
# Check if attribute exists
has(request.resource.attr.is_published)
# Check list membership
request.principal.attr.department in ["engineering", "product"]
# Date comparison
timestamp(request.resource.attr.created_at) > now() - duration("24h")
Limits
| Resource | Limit |
|---|---|
| Policies per app | 100 |
| Rules per policy | 50 |
| Test scenarios per policy | 20 |
Need higher limits? Contact support to discuss your requirements.
Troubleshooting
Access unexpectedly denied
Problem: A user should have access but is being denied.
Solution:
- Use the Test tab to simulate the access check.
- Verify the user has the required role.
- Check condition expressions for errors.
- Look for EFFECT_DENY rules that may be blocking.
Policy not being applied
Problem: Policy changes aren't affecting access checks.
Solution:
- Verify the policy is saved (check for unsaved changes).
- Ensure the resource type matches exactly.
- Check the policy version is "default" or matches your config.
Condition syntax error
Problem: CEL condition expressions are invalid.
Solution:
- Check the CEL expression syntax.
- Verify attribute names match your data model.
- Use the code editor's syntax highlighting for hints.
Related
Last Updated: January 2025